<!--跟投项目管理-->
<template>
    <div class="followProjectList">
        <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="项目名称：">
                <el-input v-model="projectName"></el-input>
            </el-form-item>
            <el-form-item label="状态：">
                <el-select v-model="status" filterable>
                    <el-option label="全部" :value="undefined"></el-option>
                    <el-option label="未启用" :value="0"></el-option>
                    <el-option label="已启用" :value="1"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="项目状态：">
                <el-select v-model="projectStatus" filterable>
                    <el-option label="全部" :value="undefined"></el-option>
                    <el-option label="即将开始" :value="0"></el-option>
                    <el-option label="申购中" :value="1"></el-option>
                    <el-option label="运营中" :value="2"></el-option>
                    <el-option label="已清算" :value="3"></el-option>
                    <el-option label="已终止" :value="4"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="success" @click="searchList" id="monitorEnter">查询</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="fn('add')">新增</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData" border>
            <el-table-column type="index" label="序号" width="50"></el-table-column>
            <el-table-column prop="projectName" label="项目名称"></el-table-column>
            <el-table-column prop="companyName" label="所属公司"></el-table-column>
            <el-table-column prop="cityName" label="所属城市"></el-table-column>
            <el-table-column label="状态">
                <template slot-scope="scope">
                    {{scope.row.enableStatus == 0 ? '未启用': ''}}
                    {{scope.row.enableStatus == 1 ? '已启用': ''}}
                </template>
            </el-table-column>
            <el-table-column label="项目状态">
                <template slot-scope="scope">
                    {{scope.row.projectStatus == 0 ? '即将开始': ''}}
                    {{scope.row.projectStatus == 1 ? '申购中': ''}}
                    {{scope.row.projectStatus == 2 ? '运营中': ''}}
                    {{scope.row.projectStatus == 3 ? '已清算': ''}}
                    {{scope.row.projectStatus == 4 ? '已终止': ''}}
                </template>
            </el-table-column>
            <el-table-column prop="updateName" label="更新人"></el-table-column>
            <el-table-column label="更新时间" prop="updateTime"></el-table-column>

            <el-table-column label="操作">
                <template slot-scope='scope'>
                    <el-button type="text" @click="fn('qiyong',scope.row)" v-show="scope.row.enableStatus == 0 && scope.row.projectStatus == 0">
                        启用
                    </el-button>
                    <el-button type="text" @click="fn('edit',scope.row)" v-show="scope.row.enableStatus == 0 && scope.row.projectStatus == 0">
                        编辑
                    </el-button>
                    <el-button type="text" @click="fn('view',scope.row)">详情</el-button>
                    <el-button type="text" @click="fn('chehui',scope.row)" v-show="scope.row.enableStatus == 1&& scope.row.projectStatus == 0">
                        撤回
                    </el-button>
                    <el-button type="text" @click="fn('zhuanrang',scope.row)">转让管理</el-button>
                    <el-button type="text" @click="fn('zhongzhi',scope.row)" v-show="scope.row.enableStatus == 1&& (scope.row.projectStatus == 1||scope.row.projectStatus == 2)">
                        终止
                    </el-button>
                    <el-button type="text" @click="fn('delete',scope.row)" v-show="scope.row.enableStatus == 0">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagebar">
            <el-pagination
                    background
                    layout="total, sizes, prev, pager, next"
                    :current-page.sync="currentPage"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="pageSize"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :total="totalSize">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    import api from '@/api/apiPath'
    import TimeComp from '@/components/common/timeComp'

    export default {
        name: "projectList",
        title:'跟投项目管理',
        components: {TimeComp},
        data() {
            return {
                projectName: undefined,
                status: undefined,
                projectStatus: undefined,
                tableData: [],
                currentPage: 1,
                pageSize: 10,
                totalSize: 0
            }
        },
        methods: {
            searchList() {
                let param = {}
                param.projectName = this.projectName
                param.enableStatus = this.status // 状态
                param.projectStatus = this.projectStatus // 项目状态
                param.pageSize = this.pageSize
                param.pageNum = this.currentPage
                this.axios.post(api.pro_selectPageList, param).then(res => {
                    let temp = res.data.data
                    this.tableData = temp.list
                    this.totalSize = temp.total
                })
            },
            // 分页器改变页码
            handleCurrentChange() {
                this.searchList()
            },
            handleSizeChange(val) {
                this.pageSize = val
                this.searchList()
            },
            fn(type, row) {
                if (type == 'add') {
                    this.$router.push({path: '/operateFollowPro', query: {type: 'add'}})
                } else if (type == 'edit') {
                    this.$router.push({path: '/operateFollowPro', query: {type: 'edit', id: row.id}})
                } else if (type == 'view') {
                    this.$router.push({path: '/followProDetails', query: {id: row.id}})
                } else if (type == 'zhuanrang') {
                    this.$router.push({path: '/transferManagement', query: {id: row.id,projectName:row.projectName}})
                } else if (type == 'qiyong') {
                    this.$confirm('确定要启用这个项目吗？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.axios.post(api.enableProject, {id: row.id}).then(() => {
                            this.$message.success('启用成功')
                            this.searchList()
                        })
                    }).catch(() => {
                    });
                } else if (type == 'chehui') {
                    this.$confirm('确定要撤回这个项目吗？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.axios.post(api.unEnableProject, {id: row.id}).then(() => {
                            this.$message.success('撤回成功')
                            this.searchList()
                        })
                    }).catch(() => {
                    });
                } else if (type == 'zhongzhi') {
                    this.$confirm('确定要终止这个项目吗？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.axios.post(api.stopProject, {id: row.id}).then(() => {
                            this.$message.success('终止成功')
                            this.searchList()
                        })
                    }).catch(() => {
                    });
                } else if (type == 'delete') {
                    this.$confirm('确定要删除这个项目吗？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.axios.post(api.deleteProject, {id: row.id}).then(() => {
                            this.$message.success('删除成功')
                            this.searchList()
                        })
                    }).catch(() => {
                    });
                }
            }
        },
        created() {
            this.searchList()
        },
        activated(){
            this.searchList()
        }
    }
</script>

<style scoped lang="stylus">
    .followProjectList {

    }
</style>
